<template>
    <ul class="todo-main">
        <row-comp :msgList="msgList"></row-comp>
    </ul>
</template>

<script>
// 引入展示每一行数据的子组件
import rowComp from "./row.vue"
export default {
    components: {
        rowComp
    },
    watch: {
        msgList: {
            handler(newV, oldV) {
                console.log('数据变了', newV)
                // 将更新后的任务数据传递给兄弟footer组件
                this.$BUS.$emit('footerData', this.msgList)
            },
            deep: true//启用深度监听
        }
    },
    data() {
        return {
            msgList: []//任务数据列表
        };
    },
    mounted() {
        // 1.监听新增任务信息
        this.$BUS.$on('addMsg', (msg) => {
            this.msgList.push(msg)
        })

        // 2.监听footer组件全选和反选操作
        this.$BUS.$on('changeAllStatus', (status) => {
            this.msgList.forEach(item => item.status = status)
        })
    },
    methods: {

    },
};
</script>

<style scoped>
.todo-main {
    margin-left: 0px;
    border: 1px solid #ddd;
    border-radius: 2px;
    padding: 0px;
}

.todo-empty {
    height: 40px;
    line-height: 40px;
    border: 1px solid #ddd;
    border-radius: 2px;
    padding-left: 5px;
    margin-top: 10px;
}

/*item*/
li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
}

li label {
    float: left;
    cursor: pointer;
}

li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
}

li button {
    float: right;
    display: none;
    margin-top: 3px;
}

li:before {
    content: initial;
}

li:last-child {
    border-bottom: none;
}

.btn {
    display: inline-block;
    padding: 4px 12px;
    margin-bottom: 0;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.btn-danger {
    color: #fff;
    background-color: #da4f49;
    border: 1px solid #bd362f;
}

.btn-danger:hover {
    color: #fff;
    background-color: #bd362f;
}

.btn:focus {
    outline: none;
}
</style>
